package com.pay.bean;

import com.tmt.annotation.parser.EnumAnnotationParser;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * 支付结果查询应答对象。
 * 注意：如trade_state不为 SUCCESS，则只返回out_trade_no（必传）和attach（选传）。
 */
@Getter
@Setter
public class WxPayResultQueryRes extends WxPayResult implements IPayResult, Serializable {

    private WxTradeState tradeState;

    private String tradeStateDesc;

    @Override
    public Map<Object, Object> initial(Map<String, String> params, String key) {
        Map<Object, Object> validParams = super.initial(params, key);
        try {
            setTradeState(WxTradeState.valueOf((String) validParams.get("trade_state")));
            setTradeStateDesc((String) validParams.get("trade_state_desc"));
        } catch (Exception ignored) {
        }
        return validParams;
    }

    @Override
    public boolean isPaid() {
        return super.isPaid() && getTradeState() == WxTradeState.SUCCESS;
    }

    @Override
    public boolean isQueryResult() {
        return true;
    }
}
